//목록리스트 4단계 액티비티
package kr.jin.zeroprojectone;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class DBListAcitiviryStep6 extends Activity {
	ArrayList <MyItemsDBList6> arList6 = new ArrayList<MyItemsDBList6>();
	ArrayList <MyItemsDBList6> arList5 = new ArrayList<MyItemsDBList6>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dblist_activity_step6);
		setAdapterList6();
	}
	
	private void setAdapterList6() {
		MyItemsDBList6 dbItem6;
		
		DBHelper dbHelper= new DBHelper(this);
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		Cursor c1 = db.rawQuery("SELECT * FROM step6", null);	
		c1.moveToFirst();	
		c1.getCount();
		
		for(int i = 0; i<c1.getCount(); i++){		
			dbItem6 = new MyItemsDBList6(c1.getInt(0), c1.getString(1), c1.getString(2), c1.getLong(3), c1.getString(4), c1.getString(5));	
			arList6.add(dbItem6);
			c1.moveToNext();			
		}
		//listHandler.sendEmptyMessage(1);
		ArrayList <MyItemsDBList6> arList5 = new ArrayList<MyItemsDBList6>();
		MyItemsDBList6 dbItem5;
		if(MainTime.textList33!=null){
			for(int i=0; i<MainTime.textList33.size(); i++){
				dbItem5 = new MyItemsDBList6(0, "", MainTime.textList33.get(i).trim(), 0L	, MainTime.textList11.get(i).trim(), MainTime.textList22.get(i).trim());
				arList5.add(dbItem5);
			}
		}
		
		DBListAdapterStep5 dblist5 = new DBListAdapterStep5(DBListAcitiviryStep6.this, R.layout.dbcustomlistview5, arList5);
		ListView DBListStep5 = (ListView)findViewById(R.id.dblist_activity_step6_listview1);
		DBListStep5.setAdapter(dblist5);
		//4단계 리스트 뷰2
		DBListAdapterStep6 dblist6 = new DBListAdapterStep6(this, R.layout.dbcustomlistview6, arList6);
		ListView DBListStep6 = (ListView)findViewById(R.id.dblist_activity_step6_listview2);
		DBListStep6.setAdapter(dblist6);
		DBListStep6.setOnItemClickListener(mItemListene6);
		
		//4단계 리스트뷰1
		/*DBListAdapterStep5 dblist5 = new DBListAdapterStep5(this, R.layout.dbcustomlistview5, arList5);
		ListView DBListStep5 = (ListView)findViewById(R.id.dblist_activity_step6_listview1);
		DBListStep5.setAdapter(dblist5);
*/
	}
	
	
	
	AdapterView.OnItemClickListener mItemListene6 = new AdapterView.OnItemClickListener() {
		
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			
			showDeleteDalog(6, position);
		}
	};

	void showDeleteDalog(int num, int position){
		FragmentManager fm6 = getFragmentManager();
		FragmentTransaction tr6 = fm6.beginTransaction();
		Fragment fg6 = fm6.findFragmentByTag("delete6");
		if(fg6!=null){
			tr6.remove(fg6);
		}
		FragmentDialogDeleteList fd6 = FragmentDialogDeleteList.newInstance(num, position);
		fd6.show(tr6, "delete6");
	}
	
	void DeleteListPositiveDialog(int num, int position){
		DBHelper dbHelper= new DBHelper(DBListAcitiviryStep6.this);
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		int i = arList6.get(position).id6;
		db.execSQL("DELETE FROM step6 WHERE _id = "+ i + ";");
	
		arList6.clear();
		dbHelper.close();
		setAdapterList6();
	};
	
	
	/*public Handler listHandler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			if(msg.what == 1){	
				ArrayList <MyItemsDBList6> arList5 = new ArrayList<MyItemsDBList6>();
				MyItemsDBList6 dbItem5;
				for(int i=0; i<InsertSchedule.textList3.size(); i++){
					dbItem5 = new MyItemsDBList6(0, "", InsertSchedule.textList3.get(i).trim(), 0L	, InsertSchedule.textList1.get(i).trim(), InsertSchedule.textList2.get(i).trim());
					arList5.add(dbItem5);
				}
				
				DBListAdapterStep5 dblist5 = new DBListAdapterStep5(DBListAcitiviryStep6.this, R.layout.dbcustomlistview5, arList5);
				ListView DBListStep5 = (ListView)findViewById(R.id.dblist_activity_step6_listview1);
				DBListStep5.setAdapter(dblist5);
			}
		}
	};*/
	
	/*public Handler listHandler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			if(msg.what == 1){	
				Log.d("1", "onHandler-2");
				ArrayList <MyItemsDBList6> arList5 = new ArrayList<MyItemsDBList6>();
				MyItemsDBList6 dbItem5;
				if(MainTime.textList33!=null){
					for(int i=0; i<MainTime.textList33.size(); i++){
						dbItem5 = new MyItemsDBList6(0, "", MainTime.textList33.get(i).trim(), 0L	, MainTime.textList11.get(i).trim(), MainTime.textList22.get(i).trim());
						arList5.add(dbItem5);
					}
				}
				
				DBListAdapterStep5 dblist5 = new DBListAdapterStep5(DBListAcitiviryStep6.this, R.layout.dbcustomlistview5, arList5);
				ListView DBListStep5 = (ListView)findViewById(R.id.dblist_activity_step6_listview1);
				DBListStep5.setAdapter(dblist5);
			}
		}
	};*/
	
	/*protected void onDestroy() {
		super.onDestroy();
		Log.d("1", "onDestroy-2");
	};*/
	
		
}
